#include <iostream>
#include<vector>
#include<string>
using namespace std;
const int N = 1e5 + 10;
int n;
int main()
{
    cin >> n;
    vector<vector<int>> p(n);
    string s;
    int op = 0;
    while (cin >> s)
    {
        
        if (s == "add")
        {
            cin >> op;
            p[0].push_back(op);
        }
        else if (s == "sync")
        {
            cin >> op;
            if(p[op].size()<p[0].size())
            p[op].push_back(p[0][p[op].size()-1]);
        }
        else
        {
            int ret = 1e9;
            //检测一下有几个元素都放进副队了
            for (int i = 1;i < n;i++)//注意不要等于n
            {
                ret = min(ret, (int)p[i].size());
            }
            cout << ret << endl;
        }
    }
    return 0;
}